package org.wu.framework.inner.lazy.orm.solon.config;

import org.noear.solon.annotation.Bean;
import org.noear.solon.annotation.Condition;
import org.noear.solon.annotation.Configuration;
import org.noear.solon.annotation.Inject;
import org.wu.framework.lazy.orm.database.lambda.LazyBaseDDLOperation;
import org.wu.framework.lazy.orm.database.lambda.LazyBaseDQLOperation;
import org.wu.framework.lazy.orm.core.config.prop.LazyDataSourceAttribute;
import org.wu.framework.lazy.orm.database.sql.expand.database.persistence.cure.*;
import org.wu.framework.lazy.orm.database.sql.expand.database.persistence.cure.lazy.LazySchemaCure;
import org.wu.framework.lazy.orm.database.sql.expand.database.persistence.cure.lazy.LazyTableColumnCure;
import org.wu.framework.lazy.orm.database.sql.expand.database.persistence.cure.lazy.LazyTableCure;

import java.util.List;

/**
 * describe :
 *
 * @author : Jia wei Wu
 * @version 1.0
 * @date : 2023/1/12 19:59
 */
@Condition(onProperty = "solon.datasource.url")
@Configuration
public class CureSolonAutoConfiguration {

    /**
     * describe 表结构治愈
     *
     * @param lazyBaseDDLOperation DDL 语言
     * @param lazyBaseDQLOperation DQL 语言
     * @return TableCure
     * @author Jia wei Wu
     * @date 2023/1/12 20:01
     **/
//    @ConditionalOnBean(value = {DataSource.class, LazyBaseDDLOperation.class, LazyBaseDQLOperation.class})
    @Bean
    @Condition(onMissingBean = TableCure.class)
    public TableCure tableCure(LazyBaseDDLOperation lazyBaseDDLOperation,
                               LazyBaseDQLOperation lazyBaseDQLOperation) {
        return new LazyTableCure(lazyBaseDDLOperation, lazyBaseDQLOperation);
    }

    /**
     * description:  表字段治愈
     *
     * @param lazyBaseDDLOperation DDL 语言
     * @param lazyBaseDQLOperation DQL 语言
     * @return TableColumnCure
     * @author 吴佳伟
     * @date: 16.1.23 01:37
     */
//    @ConditionalOnBean(value = {DataSource.class, LazyBaseDDLOperation.class, LazyBaseDQLOperation.class})
    @Bean
    @Condition(onMissingBean = TableColumnCure.class)
    public TableColumnCure tableColumnCure(LazyBaseDDLOperation lazyBaseDDLOperation,
                                           LazyBaseDQLOperation lazyBaseDQLOperation) {
        return new LazyTableColumnCure(lazyBaseDDLOperation, lazyBaseDQLOperation);
    }

    /**
     * describe schema治愈
     *
     * @param lazyBaseDDLOperation DDL 语言
     * @return SchemaCure
     * @author Jia wei Wu
     * @date 2023/1/12 20:01
     **/
    @Bean
    @Condition(onMissingBean = SchemaCure.class)
    public SchemaCure solonSchemaCure(
                                 @Inject LazyBaseDDLOperation lazyBaseDDLOperation) {
        return new LazySchemaCure( lazyBaseDDLOperation);
    }

    /**
     * describe 治愈适配器
     *
     * @param cureList 至于集合
     * @return CureAdapter
     * @author Jia wei Wu
     * @date 2023/1/12 20:01
     **/
    @Bean
    @Condition(onMissingBean = CureAdapter.class)
    public CureAdapter cureAdapter(List<Cure> cureList) {
        return new CureAdapter(cureList);
    }

}
